<!DOCTYPE html>
<html>

<head>
<#include "/common/head.html"/>
</head>

<body>
	<div class="layui-fluid">
		<div class="layui-row">
			<form method="post" class="layui-form layui-form-pane" lay-filter="form-val-filter">
				
				<div class="layui-col-md6">
			
					<div class="layui-form-item">
						<label for="name" class="layui-form-label">账号</label>
						<div class="layui-input-block">
							<input type="text" name="userName" placeholder="请输入账号"
								lay-verify="required" autocomplete="off" class="layui-input" />
						</div>
					</div>
	
					<div class="layui-form-item">
						<label for="name" class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" lay-affix="eye">
						</div>
					</div>
				</div>
				
				<div class="layui-col-md6">

					<div class="layui-form-item">
						<label for="name" class="layui-form-label">姓名</label>
						<div class="layui-input-block">
							<input type="text" name="name" placeholder="请输入姓名"
								lay-verify="required" autocomplete="off" class="layui-input" />
						</div>
					</div>
					
					<div class="layui-form-item">
						<label for="name" class="layui-form-label">状态</label>
						<div class="layui-input-block">
							<select name="disable" lay-verify="required">
								<option value="false">启用</option>
								<option value="true">禁用</option>
							</select>
						</div>
					</div>
				</div>
				
				<div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        角色设置
                    </label>
                    <div class="layui-input-block">
                    	<div id="roleset"></div>
                    </div>
                </div>

				<div class="layui-form-item">
				    <div class="layui-input-block">
				      <button type="submit" class="layui-btn" lay-submit lay-filter="add">提交</button>
				      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
				    </div>
				  </div>
				
			</form>
		</div>
	</div>
	<script>
		layui.use(function() {
			var form = layui.form;
			var transfer = layui.transfer;

			apipost('/v1/role/page',{pageSize:999},function(result){
				transfer.render({
					id:'roleset',
					elem : '#roleset',
					data : result.data,
					title: ['所属角色', '授权角色'],
					parseData : function(res) {
						return {
							"value" : res.id,
							"title" : res.name,
							"disabled" : res.disabled,
							"checked" : res.checked
						};
					}
				});
			});
			
			form.on('submit(add)', function(data) {
				var roleIds = [];
				var roles=transfer.getData('roleset');
				for(var r in roles){
					roleIds.push(roles[r].value);
				}
				var field = data.field;
				field['roleIds']=roleIds;
				field.password=hexMD5(field.password);
				winPost("/v1/user", field);
				return false;
			});

		});
	</script>
</body>

</html>